/*
 * mible_mesh_api.c
 *
 *  Created on: 2020��11��26��
 *      Author: mi
 */

#include "mible_mesh_api.h"

static mible_mesh_event_cb_t mible_mesh_event_callback_handler;

int mible_mesh_event_callback(mible_mesh_event_type_t type, void * data)
{
    if(mible_mesh_event_callback_handler != NULL){
        mible_mesh_event_callback_handler(type, (mible_mesh_event_params_t *)data);
    }
    return 0;
}

int mible_mesh_device_register_event_callback(mible_mesh_event_cb_t mible_mesh_event_cb)
{
    mible_mesh_event_callback_handler = mible_mesh_event_cb;
    return 0;
}

int mible_mesh_device_unregister_event_callback(mible_mesh_event_cb_t mible_mesh_event_cb)
{
    if(mible_mesh_event_callback_handler == mible_mesh_event_cb){
        mible_mesh_event_callback_handler = NULL;
        return 0;
    }
    return -1;
}

static mible_user_event_cb_t mible_mesh_user_state_callback_handler;

int mible_mesh_user_event_callback(uint8_t type, void * data)
{
    if(mible_mesh_user_state_callback_handler != NULL){
        mible_mesh_user_state_callback_handler(type, data);
    }
    return 0;
}

int mible_mesh_user_event_register_event_callback(mible_user_event_cb_t user_event_cb)
{
    mible_mesh_user_state_callback_handler = user_event_cb;
    return 0;
}

int mible_mesh_user_event_unregister_event_callback(mible_user_event_cb_t user_event_cb)
{
    if(mible_mesh_user_state_callback_handler == user_event_cb){
        mible_mesh_user_state_callback_handler = NULL;
        return 0;
    }
    return -1;
}

__WEAK int mible_mesh_device_deinit_stack(void)
{
    // deinit your mesh stack, close thread,free memory, and release firmware bt resource.

    return 0;
}


__WEAK int mible_mesh_device_login_done(uint8_t status)
{
    return 0;
}

__WEAK int mible_mesh_device_set_network_transmit_param(uint8_t count, uint8_t interval_steps)
{
    // set adv interval and adv transmit times
    return 0;
}

__WEAK uint8_t mible_mesh_device_get_nid(void)
{
    return 0;
}

__WEAK int mible_mesh_device_update_iv_info(uint32_t iv_index, uint8_t flags)
{
    // sync and load iv_index from application
    return 0;
}

__WEAK int mible_mesh_device_set_presub_address(mible_mesh_op_t op, uint16_t sub_addr)
{
    if(op == MIBLE_MESH_OP_ADD){
        // add subscription
    }else{
        // delete subscription
    }
    return 0;
}

__WEAK uint8_t mible_mesh_get_reset_reason(void)
{
    return 0;
}
